package com.hnhuas.salary.common;

import cn.hutool.core.convert.Convert;
import org.wf.jwtp.provider.Token;
import org.wf.jwtp.util.SubjectUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by weirdor on 2019-08-25 12:04
 */
public class BaseController {

    /**
     * 获取当前登录的userId
     */
    public Long getLoginUserId(HttpServletRequest request) {
        Token token = getLoginToken(request);
        return token == null ? null : Convert.toLong(token.getUserId());
    }

    public Token getLoginToken(HttpServletRequest request) {
        return SubjectUtil.getToken(request);
    }
}
